package cn.wuyu.baselibrary.net.http;
import io.reactivex.functions.Function;

/**
 * 用来统一处理Http的resultCode,
 * 并将HttpResult的Data部分剥离出来返回给 observer
 * Created by xuzongmeng on 2016/6/20.
 */
public class HttpResultFunc<T> implements Function<HttpResult<T>, T> {
    @SuppressWarnings({"SingleStatementInBlock","unchecked"})
    @Override
    public T apply(HttpResult<T> httpResult)  {
        if (!"000000".equals(httpResult.getCode())){
            throw new HttpException(httpResult.getCode(), httpResult.getMsg());
        }
        if (httpResult.getData()==null){
            return (T) "";
        }
//        httpResult.setServerTime();
//        Logger.json("HttpResultFunc" + httpResult);
        return httpResult.getData();//成功直接返回data数据
    }
}